<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page pageEncoding="UTF-8"%>
<div class="hero-unit">
	<spring:url var="action" value="ask" />
	<spring:message code="labels.name" htmlEscape="true" var="name" />
	<spring:message code="labels.congregation" htmlEscape="true"
		var="congregation" />
	<spring:message code="labels.email" htmlEscape="true" var="email" />
	<spring:message code="labels.phone" htmlEscape="true" var="phone" />
	<spring:message code="labels.message" htmlEscape="true" var="message" />
	<spring:message code="labels.submit" htmlEscape="true" var="submit" />

	<h1>
		<spring:message code="validate.need_validation" htmlEscape="true"
			arguments="${logged.nickname}"></spring:message>
	</h1>
	<p>
		<c:if test="${empty ask }">
			<spring:message code="validate.new" htmlEscape="true"
				var="validationMsg"></spring:message>
		</c:if>
		<c:if test="${not empty ask }">
			<spring:message code="validate.waiting" htmlEscape="true"
				var="validationMsg"></spring:message>
		</c:if>

		<spring:message code="validate.new" htmlEscape="true"
			var="newValidationMsg"></spring:message>
		<spring:message code="validate.need_validation_explanation"
			htmlEscape="true" arguments="${validationMsg}"></spring:message>
	</p>
	<p>
	<div class="census-container">
		<c:if test="${empty ask }">
			<form id="askForm" class="form-horizontal">
				<fieldset>
					<div class="control-group">
						<label class="control-label" for="name">${name}</label>
						<div class="controls">
							<input type="text" class="input-xlarge" id="name" name="name"
								placeholder="${name}" />
						</div>
					</div>
					<div class="control-group">
						<label class="control-label" for="congregation">${congregation}</label>
						<div class="controls">
							<input type="text" class="input-xlarge" id="congregation"
								name="congregation" placeholder="${congregation}" />
						</div>
					</div>
					<div class="control-group">
						<label class="control-label" for="phone">${phone}</label>
						<div class="controls">
							<input type="text" class="input-xlarge" id="phone" name="phone"
								placeholder="${phone}" />
						</div>
					</div>
					<div class="control-group">
						<label class="control-label" for="message">${message}</label>
						<div class="controls">
							<textarea class="input-xlarge" id="message" name="message"
								rows="3"></textarea>
						</div>
					</div>
					<div class="form-actions">
						<button class="btn btn-primary btn-large">${submit}</button>
					</div>
				</fieldset>
			</form>
		</c:if>
		<c:if test="${not empty ask }">

		</c:if>
	</div>
	</p>
	<script type="text/javascript">
		$(document).ready(function() {
			$("button.btn").click(function(e) {
				e.preventDefault();
				$.ajax({
					type : 'PUT',
					url : "/census/ask",
					data : $("#askForm").serialize(),
					dataType : "html"
				}).error(function(err) {
					throw err;
				}).success(function(data) {
					$(".census-container").replaceWith(data);
				});
			})

		});
	</script>
</div>
